<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;


class ArticleController extends Controller
{
    //
	public function getAdd()
	{
		return view('admin.article.add',['title' => '文章添加']);



	}

	public function postInsert(Request $request)
	{
		$data = $request -> except('_token');
		// dd($data);

		$res = DB::table('article') -> insert($data);
	
		if($res)
		{
			return redirect('/admin/article/index') -> with(['info' => '添加成功']);
		}else{
			return back() -> with(['info' => '添加失败']);
		}
	}
	public function getIndex()
	{


	}

	public function getEdit($id)
	{
		 $data = DB::table('article') -> where('id',$id) -> first();

		 // dd($data);
		return view('admin.article.edit',['title' => '文章添加','data' => $data]);		
 

	}
	public function postUpdate(Request $request,$id)
	{	

		$data = $request -> except('_token');	

		$res = DB::table('article') -> where('id',$id) -> update($data);
		if($res)
		{
			return redirect('/admin/article/index') -> with(['info' => '更新成功']);
		}else{
			return back() -> with(['info' => '更新失败']);
		}


	}


}
	
